using Sirenix.OdinInspector;
using UnityEngine;

namespace Geo.DizzyLab
{
    public class LeanController : MonoBehaviour
    {
        public Transform target;
        public float leanAngleZ = 0;
        public AnimationCurve leanSpeedCurve;

        private void Update()
        {
            var targetEuler = target.localRotation.eulerAngles;
            var angleDiff = leanAngleZ - targetEuler.z;
            var leanSpeed = leanSpeedCurve.Evaluate(angleDiff);
            targetEuler.z = Mathf.MoveTowardsAngle(targetEuler.z, leanAngleZ, leanSpeed * Time.deltaTime);
            target.localRotation = Quaternion.Euler(targetEuler);
        }
        [Button]
        public void LeanToAngleZ(float angle) => leanAngleZ = angle;
    }
    
}
